<?
	include("../main_inc.php");
	include("../../functions.inc.php");

?><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Bubble Affiliate Program</title>

<link href="../../css/admin.css" rel="stylesheet" type="text/css">
<script src="../../jscript/menuArrayAffiliate.php" language="javascript"></script>
<script src="../../jscript/clock.js" language="javascript"></script>
<script language="JavaScript" src="<?=$rootdir?>jscript/calendar1.js"></script><!-- Date only with year scrolling -->
</head>

<body onLoad="funClock();">
<?php include("../header.php"); ?>
<table width="100%" border="0" cellspacing="25" cellpadding="0">
<tr>
<td valign="top" width="240"><div id="menu"><?php include("../menu.php"); ?></div></td>
<td valign="top" align="center"><div id="title">Commission Report </div>
  <div id="search"> Enter search criteria.<br>
      <br>
      <form name="form1" method="post" action="commission.php">
        <table border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="60">Domain</td>
            <td><select name="Domains[]" size="5" multiple class="formFields" id="Domains[]">
                <option value='All' <?=($_POST['Domains'][0]=='All' ? "selected" : "");?>>All Domains</option>
                <?php
					$sq2=$r->rawQuery("SELECT id,domain FROM affiliateDomains WHERE affiliateID=$_SESSION[AffKey]");  
					while ($myrow = mysql_fetch_row($sq2)) {
						$tmp=(in_array($myrow[0],$_POST['Domains']) ? "selected" : "");
						echo"<option value='$myrow[0]' $tmp>$myrow[1]</option>";
					};
				?>
            </select></td>
            <td width="66" align="center">Search By </td>
            <td><select name="BType" class="formFields" id="SType">
                <option value='bookingDate' <?=($_POST['BType']=='bookingDate' ? "selected" : "");?>>Booking Date</option>
                <option value='checkin' <?=($_POST['BType']=='checkin' ? "selected" : "");?>>Arrival Date</option>
                
              </select>
            </td>
            <td width="50" align="center">Include </td>
            <td><select name="BInclude" class="formFields" id="BInclude">
                <option value='Booked' <?=($_POST['BInclude']=='Booked' ? "selected" : "");?>>Bookings</option>
                <option value='Cancelled' <?=($_POST['BInclude']=='Cancelled' ? "selected" : "");?>>Cancellations</option>
                <option value='All' <?=($_POST['BInclude']=='All' ? "selected" : "");?>>All Transactions</option>
            </select></td>
          </tr>
        </table>
        <br>
        <table width="271" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="60">From:</td>
            <td width="102"><input name="BFrom" type="text" class="formFields" id="BFrom" value="<?=($_POST['BFrom'] ? $_POST['BFrom'] :date("d-m-Y"));?>" size="10">
              <strong><a href="javascript:cal1.popup();"><img src="<?=$rootdir?>jscript/img/cal.gif" width="16" height="16" border="0" alt="Click Here to Pick up the date" /></a></strong></td>
            <td width="23">To:</td>
            <td width="117"><input name="BTo" type="text" class="formFields" id="BTo" value="<?=($_POST['BTo'] ? $_POST['BTo'] :date("d-m-Y"));?>" size="10">
              <strong><a href="javascript:cal2.popup();"><img src="<?=$rootdir?>jscript/img/cal.gif" width="16" height="16" border="0" alt="Click Here to Pick up the date" /></a></strong></td>
          </tr>
        </table>
        <p align="right">
          <input type="submit" name="Submit" value="Search" class="formButtons">
        </p>
        </form>
      </div>
  <div id="content">
    <table width="100%" border="0" cellpadding="5" cellspacing="1" bgcolor="#E9EEF5">
      <tr id="formHeader">
        <td align="center"><strong>Booking Date</strong></td>
        <td align="center"><strong>Arrival Date </strong></td>
        <td align="center"><strong>Domain</strong></td>
        <td align="center"><strong>Property</strong></td>
        <td width="70" align="center"><strong>Status</strong></td>
        <td width="70" align="center"><strong>Comission</strong></td>
      </tr>
      
      
      <?php
			$BSQL="";
			if($_POST['Submit']){
				if($_POST['Domains']){
					if(is_array($_POST['Domains'])){
						if($_POST['Domains'][0]!='All'){
							$BSQL.=" AND affiliateDomainsID IN (";
							$First=true;
							foreach($_POST['Domains'] as $val){
								if(!$First)$BSQL.=",";
								$BSQL.=$val;
								$First=false;
							}
							$BSQL.=") ";
						}
					}
				}
				$BSQL.=" AND ($_POST[BType]>='".SwapDates($_POST['BFrom'])."' AND $_POST[BType]<='".SwapDates($_POST['BTo'])." 23:59:59') ";  // do search by
				if($_POST['BInclude']!='All'){
					$BSQL.=" AND BStatus='$_POST[BInclude]' ";
				}
			}
			
			$Count=0;
			$Total=0;
			$r=new ReturnRecord();
			$SQL="SELECT DATE_FORMAT(bookingDate,'%a %e %b %Y'),DATE_FORMAT(checkin,'%a %e %b %Y'),domain,propertyName,affiliateCommission FROM bookings,affiliateDomains WHERE bookings.affiliateDomainsID=affiliateDomains.id AND  bookings.affiliateID='$_SESSION[AffKey]' $BSQL";
			$sq2=$r->rawQuery($SQL);  
			if($sq2){
				while ($myrow = mysql_fetch_row($sq2)) {
					$Total+=$myrow[4];
		?>
      <tr bgcolor="<?=(($Count%2)==0 ? "#FFFFFF" : "#EBEBEB"); ?>">
        <td align="center" bgcolor="#FFFFFF"><?=$myrow[0];?> </td>
        <td align="center" bgcolor="#FFFFFF"><?=$myrow[1];?> </td>
        <td align="center" bgcolor="#FFFFFF"><?=$myrow[2];?></td>
        <td align="center" bgcolor="#FFFFFF"><?=$myrow[3];?> </td>
        <td align="center" bgcolor="#FFFFFF">Paid<br>11/112007 </td>
        <td align="center" bgcolor="#FFFFFF">$<?=$myrow[4];?></td>
      </tr>
      <?
	  		};
		};
	  ?>
      <tr>
        <td bgcolor="#FFFFFF">&nbsp;</td>
        <td align="center" bgcolor="#FFFFFF">&nbsp;</td>
        <td align="center" bgcolor="#FFFFFF">&nbsp;</td>
        <td align="center" bgcolor="#FFFFFF">&nbsp;</td>
        <td align="center" bgcolor="#FFFFFF"><strong>Total:</strong></td>
        <td align="center" bgcolor="#FFFFFF">$<?=number_format($Total,2);?></td>
      </tr>
    </table>
    </div>
    <div id="results">
    <p><a href="#">EXPORT TO .CSV</a> </p>
    </div></td>
</tr>
</table>
<script language="JavaScript">
<!-- // create calendar object(s) just after form tag closed
	 // specify form element as the only parameter (document.forms['formname'].elements['inputname']);
	 // note: you can have as many calendar objects as you need for your application
	var cal1 = new calendar1(document.forms['form1'].elements['BFrom']);
	cal1.year_scroll = true;
	cal1.time_comp = false;
	var cal2 = new calendar1(document.forms['form1'].elements['BTo']);
	cal2.year_scroll = true;
	cal2.time_comp = false;
	
	

//-->
</script>
</body>
</html>
